home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / nghelp.zip / NG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  15.8 KB  |  649 lines

  1. {$A+,B-,E+,F-,I-,N-,O-,R-,V-}
  2. {$UNDEF DEBUG}
  3. {$IFDEF DEBUG} {$D+,L+,S+} {$ELSE} {$D-,L-,S-} {$ENDIF}
  4. Unit Ng;
  5.  
  6. Interface
  7.  
  8. Const ShortEntry = 0;
  9.       LongEntry  = 1;
  10.       NoEntry    = $ffff;
  11.  
  12. Type Str79   = String[79];
  13.      Str84   = String[84];
  14.      Str100  = String[100];
  15.      Str160  = String[160];
  16.      Str255  = String[255];
  17.      StrPtr  = ^Str84;
  18.  
  19.  
  20. {**********De Objecten*******************************************************}
  21.      GuideMenuOBJ     = Object
  22.       Count           : Word; {Aantal Pulldownmenus in dit Menu,Contructor}
  23.       Title           : Str84;
  24.       {********Pointers***************************}
  25.       Entrys          : Array [1..10] of Longint;
  26.       Lines           : Array [1..10] of StrPtr;
  27.       {*******************************************}
  28.  
  29.       Procedure Load(L : Longint); {Laad menuEntry}
  30.       Procedure Done;{voor straks Desctructor}
  31.       Function Entry(Nr : Word) : Longint; {Zie MMEntry}
  32.       Function Line(Nr : Word) : Str84;
  33.      End; {GuideMenuOBJ}
  34. {****************************************************************************}
  35.      GuideShortOBJ    = Object
  36.       Count           : Word; {Aantal regels, 0 als fout is opgetreden}
  37.       Parent          : Longint; {Geeft ouders van ouder in short}
  38.       Current         : Word; {Current Entry,Eigenlijk +1, Als Parent -1}
  39.                               {dan Current 65536                        }
  40.       MenuParent      : Word; {als Parent -1 dan is dit het Menu Nummer}
  41.                               {Eerste Menu is 0}
  42.       MenuLine        : Word; {Als Parent -1 Dan dit Regelnummer van menu}
  43.                               {Eerste Regel is 0}
  44.       {********Pointers***************************}
  45.       Entrys          : Array [1..512] of Longint;
  46.       Lines           : Array [1..512] of StrPtr;
  47.       {*******************************************}
  48.  
  49.       Procedure Load(L : Longint); {laad een short entry}
  50.       Procedure Done; {Voor later met destructor}
  51.       Function Line(Nr : Word) : Str84;
  52.       Function RawLine(Nr : Word) : Str84;
  53.       Function Entry(Nr : Word) : Longint;
  54.      End; {GuideShortOBJ}
  55. {****************************************************************************}
  56.      SeeAlsoOBJ        = Object
  57.       Count            : Word;
  58.  
  59.       {********Pointers***************************}
  60.       Entrys          : Array [1..21] of Longint;
  61.       Lines           : Array [1..21] of StrPtr;
  62.       {*******************************************}
  63.  
  64.       Procedure Done;
  65.       Function Line(Nr : Word) : Str84;
  66.       Function Entry(Nr : Word) : Longint;
  67.      End; {SeeAlso}
  68. {----------------------------------------------------------------------------}
  69.      GuideLongOBJ     = Object
  70.       SeeAlso         : SeeAlsoObj;
  71.       Count           : Word; {Aantal Regels}
  72.       Parent          : Longint; {Als -1 dan geen parent}
  73.       Current         : Word; {Als 65535 dan geen Current}
  74.       MenuParent      : Word; {Let op menu 4 = Menu 0}
  75.       MenuLine        : Word; {Begint bij 0 net als boven}
  76.       PrevEntry       : Longint; {-1 geen previous}
  77.       NxtEntry        : Longint; {-1 geen next}
  78.  
  79.       {********Pointers***************************}
  80.       Lines           : Array [1..512] of StrPtr;
  81.       {*******************************************}
  82.  
  83.       Procedure Load(L : Longint);
  84.       Procedure Done;
  85.       Function Line(Nr : Word) : Str84;
  86.       Function RawLine(Nr : Word) : Str84;
  87.       Function Previous : Longint;
  88.       Function Next : Longint;
  89.      End; {GuideLongOBJ}
  90.  
  91.  
  92.  
  93. {**********Einde van de Objecten*********************************************}
  94.  
  95.  
  96. Var GuideName : Str84;
  97.     Menus     : Byte; {De aantal topmenus}
  98.  
  99. {**Algemeen voor NG**********************************************************}
  100. Function  LookGuide(F : String) : String;
  101. Function  OpenGuide(GuideFileName : Str79) : Boolean;
  102. Procedure CloseGuide;
  103. Function  Credit(Regel : Byte) : Str160;
  104. Function  MenuEntry(Nr : Byte) : Longint;
  105. Function  EntryType(L : Longint) : Word;
  106. Function  GuideStrip(S : String) : String;
  107. Function  FirstEntry : Longint;
  108. {****************************************************************************}
  109.  
  110. Implementation
  111.  
  112. {Algemeen gebruikte variabelen}
  113. {Geen object omdat NG.TPU Maar een NG file Open per keer aankan}
  114. Var DecrypTabel  : Array [0..255] of Byte;
  115.     Guide        : File; {File variabele voor Norton Guide}
  116.     MEntry       : Array [1..10] of Longint; {Geeft MenuEntrys voor Menuobj.Load}
  117.     Credits      : Array [1..5] of StrPtr;{voor funtie Credit}
  118.     Buffer       : Array [0..377] of Byte;
  119.     UpDateBuffer : Boolean;
  120.     FileBufStart : Longint;
  121.     FilePtr      : Longint;
  122.     FileBufEnd   : Longint;
  123.  
  124. {***Niet voor eind user maar voor intern, menuobj****************************}
  125. {----------------------------------------------------------------------------}
  126.  
  127. {**Algemeen Voor Norton Guide*************************************************}
  128. Procedure MoveFilePtr(L : Longint);
  129. {deze procedure doet een normale seek, is gedaan om bij eventueele fout
  130.  controle dit hier te inplanteren. FilePtr wordt ook geupdate omdat enkele
  131.  funties hier vanaf hangen(bv:GuideShortOBJ.load de Entrys Lezen)}
  132. Begin
  133.  Seek(Guide,L);
  134.  if (L>=FileBufStart) And (L<=FileBufEnd) then FilePtr := L
  135.   Else UpDateBuffer := True;
  136. End;
  137.  
  138.  
  139. Procedure ReadBuffer;
  140. Var Result : Word;
  141. Begin
  142.  if Not UpDateBuffer then Seek(Guide,FilePtr);
  143.  UpDateBuffer := False;
  144.  FileBufStart := FilePos(Guide);
  145.  FilePtr := FileBufStart;
  146.  BlockRead(Guide,Buffer,Sizeof(Buffer),Result);
  147.  FileBufEnd := FilePtr + Pred(Result);
  148. End;
  149.  
  150.  
  151. Procedure MakeDecrypTabel;
  152.  
  153.   Function Decrypt(B  : Byte) : Byte;
  154.   {Decrypt byte from NG format}
  155.   Begin
  156.    if ((B Mod 32)>=16) then B := B - 16 Else B := B + 16;
  157.    if ((B Mod 16)>=8) then  B := B - 8  Else B := B + 8;
  158.    if ((B Mod 4)>=2) then   B := B - 2  Else B := B + 2;
  159.    Decrypt := B;
  160.   End;
  161.  
  162. Var Loop : Byte;
  163. Begin
  164.  For Loop := 0 to 255 Do DecrypTabel[Loop] := Decrypt(Loop);
  165. End;
  166.  
  167.  
  168. Function Read_Byte : Byte;
  169. {Read and decrypt byte}
  170. Var Tb : Byte;
  171. Begin
  172.  if (FilePtr>FileBufEnd) Or (UpDateBuffer) then
  173.   Begin
  174.    ReadBuffer;
  175.   End;
  176.  Tb := DecrypTabel[Buffer[FilePtr-FileBufStart]];
  177.  Inc(FilePtr);
  178.  Read_Byte := Tb;
  179. End;
  180.  
  181.  
  182. Function Read_Word : Word;
  183. {Read and decrypt word}
  184. Var Tw : Word;
  185.     Tb : Byte;
  186. Begin
  187.  Tb := Read_Byte;
  188.  Tw := Tb;
  189.  Tb := Read_Byte;
  190.  Inc(tw,(Tb*256));
  191.  Read_Word := Tw;
  192. End;
  193.  
  194.  
  195. Function Read_Long : Longint;
  196. {Read and decrypt longint}
  197. Var Tl : Longint;
  198.     Tw : Word;
  199. Begin
  200.  Tw := Read_Word;
  201.  Tl := Tw;
  202.  Tw := Read_Word;
  203.  Inc(Tl,(Tw*65536));
  204.  Read_Long := Tl;
  205. End;
  206. {******************Eind Norton Algemeen**************************************}
  207.  
  208. {*****Normale Functies en Procedures*****************************************}
  209. Procedure CloseGuide;
  210. Var Loop : Byte;
  211. Begin
  212. {$I-} Close(Guide); {$I+}
  213.  if IOResult <> 0 then ; {Alleen opvangen}
  214.  
  215.  For Loop := 1 to 5 Do
  216.   if Credits[Loop]<>Nil then FreeMem(Credits[Loop],Length(Credits[Loop]^)+1);
  217. End;
  218.  
  219.  
  220. Function FirstEntry : Longint;
  221. Begin
  222.  FirstEntry := 378;
  223. End;
  224.  
  225.  
  226. Function LookGuide(F : String) : String;
  227. Var S            : String;
  228.     Loop         : Word;
  229.     Result       : Word;
  230.     Guide        : File;
  231. Begin
  232.  LookGuide := ''; UpDateBuffer := True;
  233.  if F = '' then Exit;
  234.  
  235.  Assign(Guide,F);
  236. {$I-} Reset(Guide,1); {$I+}
  237.  if IOResult <> 0 then Exit; {File bestaat niet}
  238.  BlockRead(Guide,Buffer,378,Result);
  239.  if (Buffer[0]<>78) Or (Buffer[1]<>71)
  240.  Or (Result<>Sizeof(Buffer)) then
  241.  {Als de eerste 2 char niet 'NG' zijn of file is te klein dan geen NortonGuide}
  242.   Begin
  243.    Close(Guide);
  244.    Exit;
  245.   End;
  246.  
  247.  Menus := Buffer[6];
  248.  
  249.  Loop := 0;
  250.  Repeat
  251.   S[Loop+1] := Chr(Buffer[Loop+8]);
  252.   Inc(Loop);
  253.  Until (Buffer[Loop+8]=0);
  254.  S[0] := Chr(Loop); {Lengte Van de GuideName}
  255.  LookGuide := S;
  256.  
  257.  Close(Guide);
  258. End;
  259.  
  260.  
  261. Function OpenGuide(GuideFileName : Str79) : Boolean;
  262. Var Loop         : Word;
  263.  
  264.   Procedure GetCredits;
  265.   Var Loop2 : Byte;
  266.       Len   : Byte;
  267.       S     : String;
  268.   Begin
  269.    Loop := 48;
  270.    For Loop2 := 1 to 5 Do
  271.     Begin
  272.      Len := 0;
  273.      Repeat
  274.       S[Len+1] := Chr(Buffer[Loop]);
  275.       Inc(Loop); Inc(Len);
  276.      Until (Buffer[Loop-1]=0);
  277.      S[0] := Chr(Len);
  278.      GetMem(Credits[Loop2],Length(S)+1);
  279.      Credits[Loop2]^ := S;
  280.      Loop := 48 + Loop2*66;
  281.     End; {For}
  282.   End;
  283.  
  284.   Procedure Read_MenuEntrys;
  285.   Const MenuID = 2;
  286.   Var MenuNr : Byte;
  287.   Begin
  288.    MenuNr := 0;
  289.    Repeat
  290.     if Read_Word = MenuId then
  291.      Begin
  292.       Inc(MenuNr);
  293.       MEntry[MenuNr] := FilePtr - 2;{FilePos(Guide)}
  294.       MoveFilePtr(MEntry[MenuNr]+Read_Word+26);
  295.      End Else Begin
  296.                {Writeln('Error in NG File!!');}
  297.                Exit;
  298.               End;
  299.    Until (MenuNr>=Menus);
  300.   End;
  301.  
  302. Begin
  303.  OpenGuide := False;
  304.  
  305.  GuideName := LookGuide(GuideFileName);
  306.  if GuideName = '' then Exit;
  307.  Assign(Guide,GuideFileName);
  308.  Reset(Guide,1); Seek(Guide,378);
  309.  
  310.  GetCredits;
  311.  
  312. {******Zet nu de file Pointer op de juiste Plaat voor verdere acties*********}
  313.  MoveFilePtr(FirstEntry);
  314.  Read_MenuEntrys;
  315.  OpenGuide := True;
  316. End;
  317.  
  318.  
  319. Function Credit(Regel : Byte) : Str160;
  320. Begin
  321.  if (Regel>0) And (Regel<6) then
  322.   Begin
  323.    if Credits[Regel]<>Nil then Credit := Credits[Regel]^
  324.     Else Credit := '';
  325.   End Else Credit := '';
  326. End;
  327.  
  328.  
  329. Function MenuEntry(Nr : Byte) : Longint;
  330. Begin
  331.  if Nr <= Menus then MenuEntry := MEntry[Nr]
  332.   Else MenuEntry := -1;
  333. End;
  334.  
  335.  
  336. Function EntryType(L : Longint) : Word;
  337. Var Id : Word;
  338. Begin
  339.  EntryType := $ffff;
  340.  if L < 0 then Exit;
  341.  MoveFilePtr(L);
  342.  Id := Read_Word;
  343.  if (Id=0) Or (Id=1) then EntryType := Id;
  344. End;
  345.  
  346.  
  347. Function GuideStrip(S : String) : String;
  348. Var TempS : String;
  349.     Count : Word;
  350. Begin
  351.  if S = '' then Begin
  352.                  GuideStrip := S;
  353.                  Exit;
  354.                 End;
  355.  TempS := '';
  356.  Count := 0;
  357.  Repeat
  358.   Inc(Count);
  359.   if S[Count] = '^' then
  360.    Begin
  361.     Inc(Count);
  362.     Case Upcase(S[Count]) of
  363.      '^' : Begin
  364.             if (Upcase(S[Succ(Count)])='A') Or (Upcase(S[Succ(Count)])='B')
  365.             Or (Upcase(S[Succ(Count)])='U') Or (Upcase(S[Succ(Count)])='N')
  366.             then Dec(Count) Else Temps := Temps + '^';
  367.            End;
  368.      'A' : Count := Count + 2;
  369.      'B' : ;
  370.      'U' : ;
  371.      'R' : ;
  372.      'N' : Inc(Count);
  373.      Else
  374.       Dec(Count); {geen Kleur dus hoort bij tekst}
  375.     End; {Case}
  376.    End Else TempS := TempS + S[Count];
  377.  Until (Count>=256) Or (Count>=Length(S));
  378.  GuideStrip := TempS;
  379. End;
  380. {*********Einde Normale Functies en Procedures*******************************}
  381.  
  382. Procedure ReadNullString(Var S : String); {Voor intern gebruik}
  383. Var Loop : Byte;
  384. Begin
  385.  Loop := 0;
  386.  
  387.  Repeat
  388.   Inc(Loop);
  389.   S[Loop] := Char(Read_Byte);
  390.   if Loop=255 then
  391.    Begin
  392.     S[Loop] := #0;
  393.     While (Read_Byte<>0) Do ;
  394.    End;
  395.  
  396.  Until (S[Loop]=#0);
  397.  
  398.  Byte(S[0]) := Pred(Loop);
  399. End;
  400.  
  401. {****************************************************************************}
  402.  
  403. {*********Start 'GuideMenuOBJ' Object****************************************}
  404. Procedure GuideMenuOBJ.Done;
  405. Var Loop : Word;
  406. Begin
  407.  For Loop := 1 to Count Do
  408.   Begin
  409.    FreeMem(Lines[Loop],Length(Lines[Loop]^)+1);
  410.   End;
  411. End;
  412.  
  413.  
  414. Function GuideMenuOBJ.Entry(Nr : Word) : Longint;
  415. Begin
  416.  if (Nr<=Count) then Entry := Entrys[Nr]
  417.   Else Entry := -1;
  418. End;
  419.  
  420.  
  421. Function GuideMenuOBJ.Line(Nr : Word) : Str84;
  422. Begin
  423.  if (Nr<=Count) then Line := Lines[Nr]^
  424.   Else Line := '';
  425. End;
  426.  
  427.  
  428. Procedure GuideMenuOBJ.Load(L : Longint);
  429. Var Loop,
  430.     Loop2  : Word;
  431.     S      : String;
  432. Begin
  433.  MoveFilePtr(L+4); {Eerste Word is Lengte?}
  434.  Count := Read_Word;
  435.  Dec(Count);
  436.  
  437.  MoveFilePtr(L+26);
  438.  For Loop := 1 to Count Do
  439.   Begin
  440.    Entrys[Loop] := Read_Long;
  441.   End;
  442.  
  443.  Loop := FilePtr;
  444.  Loop2 := Succ(Count);
  445.  Inc(Loop,(Loop2*8));
  446.  MoveFilePtr(Loop);
  447.  
  448.  
  449.  {Title}
  450.    Loop2 := 0;
  451.    Repeat
  452.     Title[Loop2+1] := Chr(Read_Byte);
  453.     Inc(Loop2);
  454.    Until (Title[Loop2]=#0);
  455.    Title[0] := Chr(Loop2-1);
  456.  
  457.  For Loop := 1 to Count Do
  458.   Begin
  459.    Loop2 := 0;
  460.    Repeat
  461.     S[Loop2+1] := Chr(Read_Byte);
  462.     Inc(Loop2);
  463.    Until (S[Loop2]=#0);
  464.    S[0] := Chr(Loop2-1);
  465.    GetMem(Lines[Loop],Loop2);
  466.    Lines[Loop]^ := S;
  467.   End; {For}
  468. End;
  469. {*********Einde 'GuideMenuIBJ' Object****************************************}
  470.  
  471. {********GuideShortOBJ Object************************************************}
  472. Procedure GuideShortOBJ.Done;
  473. Var Loop : Word;
  474. Begin
  475.  For Loop := 1 to Count Do
  476.   Begin
  477.    FreeMem(Lines[Loop],Length(Lines[Loop]^)+1);
  478.   End;
  479. End;
  480.  
  481.  
  482. Function GuideShortOBJ.Line(Nr : Word) : Str84;
  483. Begin
  484.  if (Nr<=Count) then Line := Lines[Nr]^
  485.   Else Line := '';
  486. End;
  487.  
  488.  
  489. Function GuideShortOBJ.RawLine(Nr : Word) : Str84;
  490. Begin
  491.  if (Nr<=Count) then RawLine := Lines[Nr]^
  492.   Else RawLine := '';
  493. End;
  494.  
  495.  
  496. Function GuideShortOBJ.Entry(Nr : Word) : Longint;
  497. Begin
  498.  if (Nr<=Count) then Entry := Entrys[Nr]
  499.   Else Entry := -1;
  500. End;
  501.  
  502.  
  503. Procedure GuideShortOBJ.Load(L : Longint);
  504. Var Loop : Word;
  505.     Dump : Word;
  506.     S    : String;
  507. Begin
  508. {hier kan eventueel worden getest of het wel echt een Short Entry is,Nu dus+2}
  509.  MoveFilePtr(L+4);
  510.  Count      := Read_Word;
  511.  MoveFilePtr(L+8);
  512.  Current    := Read_Word;
  513.  Parent     := Read_Long;
  514.  MenuParent := Read_Word;
  515.  MenuLine   := Read_Word;
  516.  MoveFilePtr(L+26);
  517.  
  518.  For Loop := 1 to Count Do
  519.   Begin
  520.    MoveFilePtr(FilePtr+2);
  521.    Entrys[Loop] := Read_Long;
  522.   End;
  523.  
  524.  For Loop := 1 to Count Do
  525.   Begin
  526.    ReadNullString(S);
  527.    GetMem(Lines[Loop],Length(S)+1);
  528.    Lines[loop]^ := S;
  529.   End;
  530. End;
  531. {********Einde GuideShortOBJ Object******************************************}
  532.  
  533. {**GuideLongOBJ**************************************************************}
  534. Procedure SeeAlsoObj.Done;
  535. Var Loop : Word;
  536. Begin
  537.  For Loop := 1 to Count Do
  538.   Begin
  539.    FreeMem(Lines[Loop],Length(Lines[Loop]^)+1);
  540.   End;
  541. End;
  542.  
  543.  
  544. Function SeeAlsoObj.Line(Nr : Word) : Str84;
  545. Begin
  546.  if (Nr<=Count) then Line := Lines[Nr]^
  547.   Else Line := '';
  548. End;
  549.  
  550.  
  551. Function SeeAlsoObj.Entry(Nr : Word) : Longint;
  552. Begin
  553.  if (Nr<=Count) then Entry := Entrys[Nr]
  554.   Else Entry := -1;
  555. End;
  556.  
  557.  
  558. Procedure GuideLongOBJ.Done;
  559. Var Loop : Word;
  560. Begin
  561.  For Loop := 1 to Count Do
  562.   Begin
  563.    FreeMem(Lines[Loop],Length(Lines[Loop]^)+1);
  564.   End;
  565.  
  566.  SeeAlso.Done;
  567. End;
  568.  
  569.  
  570. Function GuideLongOBJ.Line(Nr : Word) : Str84;
  571. Begin
  572.  if (Nr<=Count) then Line := Lines[Nr]^
  573.   Else Line := '';
  574. End;
  575.  
  576.  
  577. Function GuideLongOBJ.RawLine(Nr : Word) : Str84;
  578. Begin
  579.  if (Nr<=Count) then RawLine := Lines[Nr]^
  580.   Else RawLine := '';
  581. End;
  582.  
  583.  
  584. Function GuideLongOBJ.Previous : Longint;
  585. Begin
  586.  Previous := PrevEntry;
  587. End;
  588.  
  589.  
  590. Function GuideLongOBJ.Next : Longint;
  591. Begin
  592.  Next := NxtEntry;
  593. End;
  594.  
  595.  
  596. Procedure GuideLongOBJ.Load(L : Longint);
  597. Var Loop : Word;
  598.     S    : String;
  599. Begin
  600.  MoveFilePtr(L+4);
  601.  Count         := Read_Word;
  602.  SeeAlso.Count := Read_Word;
  603.  Current       := Read_Word;
  604.  Parent        := Read_Long;
  605.  MenuLine      := Read_Word;
  606.  MenuParent    := Read_Word;
  607.  PrevEntry     := Read_Long;
  608.  NxtEntry      := Read_Long;
  609.  
  610.  For Loop := 1 to Count Do
  611.   Begin
  612.    ReadNullString(S);
  613.    GetMem(Lines[Loop],Length(S)+1);
  614.    Lines[Loop]^ := S;
  615.   End;
  616.  
  617.  if SeeAlso.Count <> 0 then
  618.   Begin
  619.    With SeeAlso Do
  620.     Begin
  621.      Count := Read_Word;
  622.  
  623.      For Loop := 1 to Count Do
  624.       if Loop <21 then
  625.        Begin
  626.         SeeAlso.Entrys[Loop] := Read_Long
  627.        End Else MoveFilePtr(Filepos(Guide)+4);
  628.  
  629.      For Loop := 1 to Count Do
  630.       Begin
  631.        if Loop<21 then
  632.         Begin
  633.          ReadNullString(S);
  634.          GetMem(SeeAlso.Lines[Loop],Length(S)+1);
  635.          SeeAlso.Lines[Loop]^ := S;
  636.         End;
  637.       End; {For}
  638.     End; {With}
  639.   End;
  640. End;
  641. {****************************************************************************}
  642.  
  643.  
  644. Begin {Init NG Unit}
  645.  For Menus := 1 to 5 Do Credits[Menus] := Nil;
  646.  GuideName := '';
  647.  Menus := 0;
  648.  MakeDecrypTabel;
  649. End.  {Init NG Unit}